﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.IO;
namespace BAMLFileTransfer
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnDowload_Click(object sender, EventArgs e)
        {
            try
            {
                this.btnDowload.Enabled = false;
                this.btnDowload.Text = "Downloading...";
                FTPConn fc = new FTPConn(ConfigurationManager.AppSettings["host"], ConfigurationManager.AppSettings["usrname"], ConfigurationManager.AppSettings["pwd"], ConfigurationManager.AppSettings["localDirectory"], ConfigurationManager.AppSettings["serverDirectory"]);
                fc.connect();
                this.btnDowload.Enabled = true;
                this.btnDowload.Text = "Download Now";
                if (File.Exists(ConfigurationManager.AppSettings["localDirectory"] + ConfigurationManager.AppSettings["settingFolderName"] + "log.txt"))
                {
                    lbna.Visible = false;
                    lbTime.Text = File.ReadAllText(ConfigurationManager.AppSettings["localDirectory"] + ConfigurationManager.AppSettings["settingFolderName"] + "log.txt");
                }
                else
                {
                    lbna.Visible = true;
                    lbTime.Text = "";
                }
            }
            catch (Exception ex)
            {
                lbTime.Text = ex.ToString();
            }
         }

        private void MainForm_Load(object sender, EventArgs e)
        {
            lbna.Visible = false;
            if (File.Exists(ConfigurationManager.AppSettings["localDirectory"] + ConfigurationManager.AppSettings["settingFolderName"] + "log.txt"))
            {
                string time = File.ReadAllText(ConfigurationManager.AppSettings["localDirectory"] + ConfigurationManager.AppSettings["settingFolderName"] + "log.txt");
                lbTime.Text = time;
                lbna.Visible = false;
            }
            else{
                 lbTime.Text = "";
                 lbna.Visible = true;
            }
  
        }
    }
}
